package com.whfc.ms.api.fse.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.ListData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.fse.dto.FseLiftDataDTO;
import com.whfc.fse.dto.FseLiftDataLogDTO;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.fse.service.MsFseLiftDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @DESCRIPTION 升降机监控数据接口
 * @AUTHOR GuoDong_Sun
 * @DATE 2020/4/10
 */
@RequiresPermissions("fse/lift")
@RestController
@RequestMapping("/ms/api/lift/data")
public class FseLiftDataController extends BaseController {
    @Autowired
    private MsFseLiftDataService msFseLiftDataService;

    @GetMapping("/latest")
    public Result latest(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                         @RequestParam("liftId") Integer liftId) {
        logger.info("获取升降机及时数据,loginer:{},liftId:{}", user.getUsername(), liftId);
        List<FseLiftDataDTO> fseLiftDataList = msFseLiftDataService.latest(liftId);
        return ResultUtil.success(new ListData<>(fseLiftDataList));
    }

    @GetMapping("/log")
    public Result log(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @RequestParam("liftId") Integer liftId,
                      @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam("date") Date date) {
        logger.info("获取升降机监控的历史数据,loginer:{},liftId:{},date:{}", user.getUsername(), liftId, date);
        ListData<FseLiftDataLogDTO> listData = msFseLiftDataService.log(liftId, date);
        return ResultUtil.success(listData);
    }

}
